import Mock from 'mockjs'

const count = 100
const userList = []
const roleList = []
for (let i = 0; i < 10; i++) {
  roleList.push(
    Mock.mock({
      id: i + 1,
      roleName: '@first',
    })
  )
}
for (let i = 0; i < count; i++) {
  userList.push(
    Mock.mock({
      id: '@increment',
      username: '@first',
      pwd: '12345678',
      phoneNumber: '',
      email: '',
      locked: 1,
      roleNames: ['admin', 'editeor'],
    })
  )
}

export default  [
  {
    url: '/sysUser/list',
    type: 'post',
    response(config) {
      const page = 1 
      const pageSize = 20 
      const keyword=""
      const mockList = userList.filter(
        (item) => !(keyword && item.keyword.indexOf(keyword) < 0)
      )
      const list = mockList.filter(
        (item, index) =>
          index < pageSize * page && index >= pageSize * (page - 1)
      )
      return {
        code: 1,
        msg: 'success',
        data: {
          total: userList.length,
          items: list,
        },
      }
    },
  },
  {
    url: '/sysUser/addUser',
    type: 'post',
    response: (_) => {
      return {
        code: 1,
        data: 'success',
      }
    },
  },
  {
    url: '/sysUser/getUserVoById',
    type: 'get',
    response: () => {
      return {
        code: 1,
        data: Mock.mock({
          id: '@increment',
          username: 'admin',
          pwd: '12345678',
          phoneNumber: 'Si8zOXJ0VmJTSjQzTnlXaXdJVFhIQT09',
          email: 'Rkh0L3BQaXF5aGwvSmxsb3o3MWFqdz09',
          'locked|1': [0, 1],
          roleIds: [1, 2],
        }),
        msg: '操作成功',
      }
    },
  },
  {
    url: '/sysRole/getRoleByUserId',
    type: 'get',
    response: (_) => {
      return {
        code: 1,
        data: roleList,
      }
    },
  },
  {
    url: '/sysUser/delUser',
    type: 'post',
    response: (_) => {
      return {
        code: 1,
        data: 'success',
      }
    },
  },
  {
    url: '/sysUser/lockUser',
    type: 'post',
    response: (_) => {
      return {
        code: 0,
        data: 'error',
        msg: '错误了',
      }
    },
  },
  {
    url: '/UserManage/resetPwd',
    type: 'post',
    response: (_) => {
      return {
        code: 1,
        data: 'success',
      }
    },
  },
]
